import axios from 'axios'
import { showToast } from 'vant'
const request = axios.create({ baseURL: 'https://meikou-api.itheima.net/', timeout: 5000 })
request.interceptors.request.use(
  (config) => {
    try {
      const user = mk.queryUser()
      if (user.token) {
        config.headers.Authorization = `Bearer ${user.token}`
      }
    } catch (e) {
      showToast({ message: '美蔻SDK异常' })
    }
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)
request.interceptors.response.use(
  (res) => {
    return res
  },
  (error) => {
    return Promise.reject(error)
  }
)

export { request }
